package com.hsp.poly_.PolyParameter;

public class PolyParameter {
    public static void main(String[] args) {
        Worker worker = new Worker("tom", 2500);
        Manager manager = new Manager("milan", 5000, 200000);
        manager.setBonus(600000);
        PolyParameter polyParameter = new PolyParameter();
        polyParameter.showEmpSalary(worker);
        polyParameter.showEmpSalary(manager);
        polyParameter.testWork(worker);
        polyParameter.testWork(manager);

    }

    public void showEmpSalary(Employee e) {//动态绑定，只要传入的是本类或子类都行
        System.out.println(e.getSalary());//会获取对应类的方法
    }
    public void testWork(Employee e) {
        if (e instanceof Manager) {//传入的子类e是右边类的实例
            ((Manager) e).manage();
        } else if (e instanceof Worker) {
            ((Worker) e).work();//向下转型的操作
        } else {
            System.out.println("输入类型错误");
        }
    }
}

